#include<iostream>
#include<unistd.h>
#include<vector>
#include<sys/types.h>

using namespace std;

void prun(pid_t rid)
{
    while(1)
    {
        cout<<"我是一个父进程，pid为:"<<getpid()<<" ,ppid为:"<<getppid()<<endl;
        cout<<"fork返回id为:"<<rid<<endl;
        sleep(2);
    }
}


void run()
{
    while(1)
    {
        cout<<"我是一个子进程，pid为:"<<getpid()<<" ,ppid为:"<<getppid()<<endl;
        sleep(2);
    }
}


int main()
{
    ////cout<<"hello PCB"<<endl;
    //while(1)
    //{
    //    //cout<<"hello process!"<<endl;
    //    sleep(1);
    //}

    pid_t pid = fork();

    if(pid != 0)
    {
        prun(pid);
    }
    else
    {
        run();
    }




    return 0;
}
